﻿using AyaWo.Commen;
using AyaWo.DAL;
using BellesLettres;
using Qbqqban;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XiuLetters;
using YuLe163Hot;

namespace AyaWo.ToDo
{
    public class ToDoSerVice
    {
        public static void Initiali()
        {
            new ToDoSerVice().Initiali1();
        }

        public void Initiali1()
        {
            var dt = DateTime.Now;

           
            bool _lock = true;
            if (_lock)
            {
                _lock = false; 

                #region 散文网爬虫 
                try
                {
                    BellesLettresSpler blsp = new BellesLettresSpler();
                    var blspDat = DatHelper<int>.GetDatList(blsp.DatName + ".dat");
                    if (blspDat != null || blspDat.Count() != 0)
                    {
                        Logser.Info($"{ blsp.DatName}.dat:{fastJSON.JSON.Instance.ToJSON(blspDat)}");
                        if (blspDat.Contains(dt.Hour))
                        {
                            blsp.Initiali();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logser.Error("散文网爬虫: " + ex.Message);
                }
                #endregion

                #region 秀虫
                try
                {
                    XiuLettersSpler xlsp = new XiuLettersSpler();
                    var xlspDat = DatHelper<int>.GetDatList(xlsp.DatName + ".dat");
                    if (xlspDat != null && xlspDat.Count() != 0)
                    {
                        Logser.Info($"{ xlsp.DatName}.dat:{fastJSON.JSON.Instance.ToJSON(xlspDat)}");
                        if (xlspDat.Contains(dt.Hour))
                        {
                            xlsp.Initiali();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logser.Error("秀虫: " + ex.Message);
                }
                #endregion

                #region 网易娱乐Top
                try
                {
                    YuLe163HotSpler ylsp = new YuLe163HotSpler();
                    var ylspDat = DatHelper<int>.GetDatList(ylsp.DatName + ".dat");
                    if (ylspDat != null || ylspDat.Count() != 0)
                    {
                        Logser.Info($"{ ylsp.DatName}.dat:{fastJSON.JSON.Instance.ToJSON(ylspDat)}");
                        if (ylspDat.Contains(dt.Hour))
                        {
                            ylsp.Initiali();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logser.Error("网易娱乐Top: " + ex.Message);
                }
                #endregion

                #region qqban发布
                try
                {
                    QbqqbanAuto qqban = new QbqqbanAuto();
                    var qqbDat = DatHelper<int>.GetDatList(qqban.DatName + ".dat");
                    if (qqbDat != null || qqbDat.Count() != 0)
                    {
                        Logser.Info($"{ qqban.DatName}.dat:{fastJSON.JSON.Instance.ToJSON(qqbDat)}");
                        if (qqbDat.Contains(dt.Hour))
                        {
                            qqban.Initiali();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logser.Error("qqban发布: " + ex.Message);
                }
                #endregion

            }
        }
    }
}
